﻿Public Class FormQLCaTruc

    Private Sub FormQLCaTruc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'QL_BidaDataNhanVien.NhanVien' table. You can move, or remove it, as needed.
        Me.NhanVienTableAdapter.Fill(Me.QL_BidaDataNhanVien.NhanVien)

        Dim dt As DataTable
        Dim ctBUS As New BUS.CaTrucBUS
        dt = ctBUS.LoadTinhTrangCaTruc()
        gcCaTruc.DataSource = dt

        Dim rpt As New ReportCaTrucTrongNgay
        rpt.SetParameterValue("@ThoiGian", DateTime.Now)
        crvCaTruc.ReportSource = rpt

    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Try
            Dim dt As DataTable
            Dim nvBUS As New BUS.NhanVienBUS
            dt = nvBUS.LoadNV_MANV(glueNhanVien.EditValue.ToString())
            If dt.Rows(0)(3).ToString() <> "1" Then
                MessageBox.Show("Nhân viên đã nghỉ hẳn hoặc trong ca trực")
            Else
                Dim ctBUS As New BUS.CaTrucBUS
                ctBUS.BatDauCaTruc(glueNhanVien.EditValue.ToString())
                dt = ctBUS.LoadTinhTrangCaTruc()
                gcCaTruc.DataSource = dt
                MessageBox.Show("Thành công")
            End If
        Catch ex As Exception
            MessageBox.Show("Không thực hiện được thông tác")
        End Try
    End Sub

    Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
        Try
            Dim dt As DataTable
            Dim nvBUS As New BUS.NhanVienBUS
            dt = nvBUS.LoadNV_MANV(glueNhanVien.EditValue.ToString())
            If dt.Rows(0)(3).ToString() <> "2" Then
                MessageBox.Show("Nhân viên đã nghỉ hẳn hoặc chưa vào ca trực")
            Else
                Dim ctBUS As New BUS.CaTrucBUS
                ctBUS.KetThucCaTruc(glueNhanVien.EditValue.ToString())
                dt = ctBUS.LoadTinhTrangCaTruc()
                gcCaTruc.DataSource = dt
                Dim rpt As New ReportCaTrucTrongNgay
                rpt.SetParameterValue("@ThoiGian", DateTime.Now)
                crvCaTruc.ReportSource = rpt

                MessageBox.Show("Thành công")
            End If
        Catch ex As Exception
            MessageBox.Show("Không thực hiện được thông tác")
        End Try
    End Sub
End Class